<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
</head>

<body>
  <div id="app">

    <ul>
      <li @click="tab('Child1')">tab1</li>
      <li @click="tab('Child2')">tab2</li>
      <li @click="tab('Child3')">tab3</li>
    </ul>

    <!-- 动态组件 -->
    <!-- 状态保持 -->
    <keep-alive>
      <component :is="componentname"></component>
    </keep-alive>
  </div>

  <script id="child1" type="text/x-template">
    <div>
        tab1
        <input type="text" v-model="userame">

    </div>
  </script>
  <script id="child2" type="text/x-template">
    <div>
        Tab2
        <input type="text" v-model="userame">

    </div>
  </script>
  <script id="child3" type="text/x-template">
    <div>
        Tab3
        <input type="text" v-model="userame">

    </div>
  </script>
  <script src="./js/vue.js"></script>
  <script>


    const Child1 = {
      template: '#child1'
    }
    const Child2 = {
      template: '#child2'
    }
    const Child3 = {
      template: '#child3'
    }



    // 根组件
    const app = new Vue({
      el: '#app',
      data: {
        componentname: 'Child1'
      },
      components: { Child1, Child2, Child3 },
      methods: {
        tab(name) {
          this.componentname = name
        }
      }
    })
  </script>
</body>

</html>